package com.guoxin.part1.chapter3;

import java.util.concurrent.TimeUnit;

/**
 * 线程interrupt
 *
 * @author guoxin
 * @date 2019/8/27
 */
public class ThreadInterrupt2 {
    public static void main(String[] args) {
        // 判断当前线程是否被中断
        System.out.println("Main thread is interrupted?" + Thread.interrupted());
        // 中断当前线程
        Thread.currentThread().interrupt();
        // 判断当前线程是否已经被中断
        System.out.println("Main thread is interrupted?" + Thread.currentThread().isInterrupted());

        try {
            // 当前线程执行可中断方法
            TimeUnit.MINUTES.sleep(1);
        } catch (InterruptedException e) {
            System.out.println("I will be interrupted still.");
        }
    }
}
